package app

import (
	"github.com/cuiyuanxin/airuisi-admin/pkg/config"
	"github.com/gin-gonic/gin"
	"github.com/spf13/cast"
)

func GetPage(c *gin.Context) int {
	page := cast.ToInt(c.Query("page"))
	if page <= 0 {
		return 1
	}

	return page
}

func GetLimit(c *gin.Context) int {
	limit := cast.ToInt(c.Query("limit"))
	if limit <= 0 {
		return config.AppLimit
	}

	return limit
}

func GetPageOffset(page, limit int) int {
	result := 0
	if page > 0 {
		result = (page - 1) * limit
	}

	return result
}
